package com.own.core.object.admin;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.own.core.html.form.object.ObjectField;
import com.own.core.html.form.textField.TextField;
import com.own.core.object.Dao;
import com.own.core.object.User;

@Entity
@Table(name = "core_group")
public class Group extends Dao {

	private long id;

	@TextField(required = true)
	private String name;

	@ObjectField(iconSupport = true)
	private Set<User> users;

	@ObjectField(iconSupport = true)
	private Set<Role> roles;

	
	public Group(){}
	
	public Group(String name){
		this.name=name;
	}
	
	
	@Id
	@GeneratedValue(strategy = GenerationType.TABLE)
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@Column(name = "name")
	public String getName() {
		return name;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "user_group", joinColumns = { @JoinColumn(name = "group_id", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "user_id", referencedColumnName = "id") })
	public Set<User> getUsers() {
		return users;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "group_role", joinColumns = { @JoinColumn(name = "group_id", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "role_id", referencedColumnName = "id") })
	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	public void setUsers(Set<User> users) {
		this.users = users;
	}

	public void setName(String name) {
		this.name = name;
	}

	
	
	
}
